/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 - 2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/

package com.genia.toolbox.web.jndi_config;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;

/**
 * a fake {@link Connection} that is used to transmit informations from the
 * application server to an application.
 */
class StringContainerConnection
    implements Connection
{

  /**
   * the properties to expose.
   */
  final Properties properties;



  /**
   * constructor.
   * 
   * @param properties
   *          the properties to expose.
   */
  StringContainerConnection(final Properties properties)
  {
    this.properties = properties;
  }



  /**
   * Do nothing.
   * 
   * @see java.sql.Connection#clearWarnings()
   */
  public void clearWarnings()
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @see java.sql.Connection#close()
   */
  public void close()
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @see java.sql.Connection#commit()
   */
  public void commit()
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @return a new default <code>Statement</code> object
   * @see java.sql.Connection#createStatement()
   */
  public Statement createStatement()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param resultSetType
   *          a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>
   *          , <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
   *          <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
   * @param resultSetConcurrency
   *          a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code>
   *          or <code>ResultSet.CONCUR_UPDATABLE</code>
   * @return a new <code>Statement</code> object that will generate
   *         <code>ResultSet</code> objects with the given type and concurrency
   * @see java.sql.Connection#createStatement(int, int)
   */
  public Statement createStatement(int resultSetType, int resultSetConcurrency)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param resultSetType
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.TYPE_FORWARD_ONLY</code>,
   *          <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
   *          <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
   * @param resultSetConcurrency
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.CONCUR_READ_ONLY</code> or
   *          <code>ResultSet.CONCUR_UPDATABLE</code>
   * @param resultSetHoldability
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
   *          <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
   * @return a new <code>Statement</code> object that will generate
   *         <code>ResultSet</code> objects with the given type, concurrency,
   *         and holdability
   * @see java.sql.Connection#createStatement(int, int, int)
   */
  public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return the current state of this <code>Connection</code> object's
   *         auto-commit mode
   * @see java.sql.Connection#getAutoCommit()
   */
  public boolean getAutoCommit()
  {
    // Do nothing.
    return false;
  }



  /**
   * Do nothing.
   * 
   * @return the current catalog name or <code>null</code> if there is none
   * @see java.sql.Connection#getCatalog()
   */
  public String getCatalog()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return the holdability, one of
   *         <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
   *         <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
   * @see java.sql.Connection#getHoldability()
   */
  public int getHoldability()
  {
    // Do nothing.
    return 0;
  }



  /**
   * Do nothing.
   * 
   * @return a <code>DatabaseMetaData</code> object for this
   *         <code>Connection</code> object
   * @see java.sql.Connection#getMetaData()
   */
  public DatabaseMetaData getMetaData()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return the current transaction isolation level, which will be one of the
   *         following constants:
   *         <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
   *         <code>Connection.TRANSACTION_READ_COMMITTED</code>,
   *         <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
   *         <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
   *         <code>Connection.TRANSACTION_NONE</code>.
   * @see java.sql.Connection#getTransactionIsolation()
   */
  public int getTransactionIsolation()
  {
    // Do nothing.
    return 0;
  }



  /**
   * Do nothing.
   * 
   * @return the <code>java.util.Map</code> object associated with this
   *         <code>Connection</code> object
   * @see java.sql.Connection#getTypeMap()
   */
  public Map<String, Class<?>> getTypeMap()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return the first <code>SQLWarning</code> object or <code>null</code> if
   *         there are none
   * @see java.sql.Connection#getWarnings()
   */
  public SQLWarning getWarnings()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return <code>true</code> if this <code>Connection</code> object is closed;
   *         <code>false</code> if it is still open
   * @see java.sql.Connection#isClosed()
   */
  public boolean isClosed()
  {
    // Do nothing.
    return false;
  }



  /**
   * Do nothing.
   * 
   * @return <code>true</code> if this <code>Connection</code> object is
   *         read-only; <code>false</code> otherwise
   * @see java.sql.Connection#isReadOnly()
   */
  public boolean isReadOnly()
  {
    // Do nothing.
    return false;
  }



  /**
   * returns the property associated with the given name. This the only
   * implemented method.
   * 
   * @param sql
   *          the name of the propery to retrieve
   * @return the property associated with the given name
   */
  public String nativeSQL(String sql)
  {
    return properties.getProperty(sql);
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          an SQL statement that may contain one or more '?' parameter
   *          placeholders. Typically this statement is a JDBC function call
   *          escape string.
   * @return a new default <code>CallableStatement</code> object containing the
   *         pre-compiled SQL statement
   * @see java.sql.Connection#prepareCall(java.lang.String)
   */
  public CallableStatement prepareCall(String sql)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          a <code>String</code> object that is the SQL statement to be sent
   *          to the database; may contain on or more ? parameters
   * @param resultSetType
   *          a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>
   *          , <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
   *          <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
   * @param resultSetConcurrency
   *          a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code>
   *          or <code>ResultSet.CONCUR_UPDATABLE</code>
   * @return a new <code>CallableStatement</code> object containing the
   *         pre-compiled SQL statement that will produce <code>ResultSet</code>
   *         objects with the given type and concurrency
   * @see java.sql.Connection#prepareCall(java.lang.String, int, int)
   */
  public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          a <code>String</code> object that is the SQL statement to be sent
   *          to the database; may contain on or more ? parameters
   * @param resultSetType
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.TYPE_FORWARD_ONLY</code>,
   *          <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
   *          <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
   * @param resultSetConcurrency
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.CONCUR_READ_ONLY</code> or
   *          <code>ResultSet.CONCUR_UPDATABLE</code>
   * @param resultSetHoldability
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
   *          <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
   * @return a new <code>CallableStatement</code> object, containing the
   *         pre-compiled SQL statement, that will generate
   *         <code>ResultSet</code> objects with the given type, concurrency,
   *         and holdability
   * @see java.sql.Connection#prepareCall(java.lang.String, int, int, int)
   */
  public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          an SQL statement that may contain one or more '?' IN parameter
   *          placeholders
   * @return a new default <code>PreparedStatement</code> object containing the
   *         pre-compiled SQL statement
   * @see java.sql.Connection#prepareStatement(java.lang.String)
   */
  public PreparedStatement prepareStatement(String sql)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          an SQL statement that may contain one or more '?' IN parameter
   *          placeholders
   * @param autoGeneratedKeys
   *          a flag indicating whether auto-generated keys should be returned;
   *          one of <code>Statement.RETURN_GENERATED_KEYS</code> or
   *          <code>Statement.NO_GENERATED_KEYS</code>
   * @return a new <code>PreparedStatement</code> object, containing the
   *         pre-compiled SQL statement, that will have the capability of
   *         returning auto-generated keys
   * @see java.sql.Connection#prepareStatement(java.lang.String, int)
   */
  public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          an SQL statement that may contain one or more '?' IN parameter
   *          placeholders
   * @param columnIndexes
   *          an array of column indexes indicating the columns that should be
   *          returned from the inserted row or rows
   * @return a new <code>PreparedStatement</code> object, containing the
   *         pre-compiled statement, that is capable of returning the
   *         auto-generated keys designated by the given array of column indexes
   * @see java.sql.Connection#prepareStatement(java.lang.String, int[])
   */
  public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          an SQL statement that may contain one or more '?' IN parameter
   *          placeholders
   * @param columnNames
   *          an array of column names indicating the columns that should be
   *          returned from the inserted row or rows
   * @return a new <code>PreparedStatement</code> object, containing the
   *         pre-compiled statement, that is capable of returning the
   *         auto-generated keys designated by the given array of column names
   * @see java.sql.Connection#prepareStatement(java.lang.String,
   *      java.lang.String[])
   */
  public PreparedStatement prepareStatement(String sql, String[] columnNames)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          a <code>String</code> object that is the SQL statement to be sent
   *          to the database; may contain one or more ? IN parameters
   * @param resultSetType
   *          a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>
   *          , <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
   *          <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
   * @param resultSetConcurrency
   *          a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code>
   *          or <code>ResultSet.CONCUR_UPDATABLE</code>
   * @return a new PreparedStatement object containing the pre-compiled SQL
   *         statement that will produce <code>ResultSet</code> objects with the
   *         given type and concurrency
   * @see java.sql.Connection#prepareStatement(java.lang.String, int, int)
   */
  public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param sql
   *          a <code>String</code> object that is the SQL statement to be sent
   *          to the database; may contain one or more ? IN parameters
   * @param resultSetType
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.TYPE_FORWARD_ONLY</code>,
   *          <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
   *          <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
   * @param resultSetConcurrency
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.CONCUR_READ_ONLY</code> or
   *          <code>ResultSet.CONCUR_UPDATABLE</code>
   * @param resultSetHoldability
   *          one of the following <code>ResultSet</code> constants:
   *          <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
   *          <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
   * @return a new <code>PreparedStatement</code> object, containing the
   *         pre-compiled SQL statement, that will generate
   *         <code>ResultSet</code> objects with the given type, concurrency,
   *         and holdability
   * @see java.sql.Connection#prepareStatement(java.lang.String, int, int, int)
   */
  public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param savepoint
   *          the <code>Savepoint</code> object to be removed
   * @see java.sql.Connection#releaseSavepoint(java.sql.Savepoint)
   */
  public void releaseSavepoint(Savepoint savepoint)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @see java.sql.Connection#rollback()
   */
  public void rollback()
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param savepoint
   *          the <code>Savepoint</code> object to roll back to
   * @see java.sql.Connection#rollback(java.sql.Savepoint)
   */
  public void rollback(Savepoint savepoint)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param autoCommit
   *          <code>true</code> to enable auto-commit mode; <code>false</code>
   *          to disable it
   * @see java.sql.Connection#setAutoCommit(boolean)
   */
  public void setAutoCommit(boolean autoCommit)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param catalog
   *          the name of a catalog (subspace in this <code>Connection</code>
   *          object's database) in which to work
   * @see java.sql.Connection#setCatalog(java.lang.String)
   */
  public void setCatalog(String catalog)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param holdability
   *          a <code>ResultSet</code> holdability constant; one of
   *          <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
   *          <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
   * @see java.sql.Connection#setHoldability(int)
   */
  public void setHoldability(int holdability)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param readOnly
   *          <code>true</code> enables read-only mode; <code>false</code>
   *          disables it
   * @see java.sql.Connection#setReadOnly(boolean)
   */
  public void setReadOnly(boolean readOnly)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @return the new <code>Savepoint</code> object
   * @see java.sql.Connection#setSavepoint()
   */
  public Savepoint setSavepoint()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param name
   *          a <code>String</code> containing the name of the savepoint
   * @return the new <code>Savepoint</code> object
   * @see java.sql.Connection#setSavepoint(java.lang.String)
   */
  public Savepoint setSavepoint(String name)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param level
   *          one of the following <code>Connection</code> constants:
   *          <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
   *          <code>Connection.TRANSACTION_READ_COMMITTED</code>,
   *          <code>Connection.TRANSACTION_REPEATABLE_READ</code>, or
   *          <code>Connection.TRANSACTION_SERIALIZABLE</code>. (Note that
   *          <code>Connection.TRANSACTION_NONE</code> cannot be used because it
   *          specifies that transactions are not supported.)
   * @see java.sql.Connection#setTransactionIsolation(int)
   */
  public void setTransactionIsolation(int level)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param map
   *          the <code>java.util.Map</code> object to install as the
   *          replacement for this <code>Connection</code> object's default type
   *          map
   * @see java.sql.Connection#setTypeMap(java.util.Map)
   */
  public void setTypeMap(Map<String, Class<?>> map)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param typeName
   *          the SQL name of the type the elements of the array map to. The
   *          typeName is a database-specific name which may be the name of a
   *          built-in type, a user-defined type or a standard SQL type
   *          supported by this database. This is the value returned by
   *          <code>Array.getBaseTypeName</code>
   * @param elements
   *          the elements that populate the returned object
   * @return an Array object whose elements map to the specified SQL type
   * @see java.sql.Connection#createArrayOf(java.lang.String,
   *      java.lang.Object[])
   */
  public Array createArrayOf(String typeName, Object[] elements)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return An object that implements the <code>Clob</code> interface
   * @see java.sql.Connection#createBlob()
   */
  public Blob createBlob()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return An object that implements the <code>Clob</code> interface
   * @see java.sql.Connection#createClob()
   */
  public Clob createClob()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return An object that implements the <code>NClob</code> interface
   * @see java.sql.Connection#createNClob()
   */
  public NClob createNClob()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return An object that implements the <code>SQLXML</code> interface
   * @see java.sql.Connection#createSQLXML()
   */
  public SQLXML createSQLXML()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param typeName
   *          the SQL type name of the SQL structured type that this
   *          <code>Struct</code> object maps to. The typeName is the name of a
   *          user-defined type that has been defined for this database. It is
   *          the value returned by <code>Struct.getSQLTypeName</code>.
   * @param attributes
   *          the attributes that populate the returned object
   * @return a Struct object that maps to the given SQL type and is populated
   *         with the given attributes
   * @see java.sql.Connection#createStruct(java.lang.String, java.lang.Object[])
   */
  public Struct createStruct(String typeName, Object[] attributes)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @return A <code>Properties</code> object that contains the name and current
   *         value of each of the client info properties supported by the
   *         driver.
   * @see java.sql.Connection#getClientInfo()
   */
  public Properties getClientInfo()
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param name
   *          The name of the client info property to retrieve
   * @return The value of the client info property specified
   * @see java.sql.Connection#getClientInfo(java.lang.String)
   */
  public String getClientInfo(String name)
  {
    // Do nothing.
    return null;
  }



  /**
   * Do nothing.
   * 
   * @param timeout
   *          - The time in seconds to wait for the database operation used to
   *          validate the connection to complete. If the timeout period expires
   *          before the operation completes, this method returns false. A value
   *          of 0 indicates a timeout is not applied to the database operation.
   * @return true if the connection is valid, false otherwise
   * @see java.sql.Connection#isValid(int)
   */
  public boolean isValid(int timeout)
  {
    // Do nothing.
    return false;
  }



  /**
   * Do nothing.
   * 
   * @param properties
   *          the list of client info properties to set
   * @see java.sql.Connection#setClientInfo(java.util.Properties)
   */
  public void setClientInfo(Properties properties)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param name
   *          The name of the client info property to set
   * @param value
   *          The value to set the client info property to. If the value is
   *          null, the current value of the specified property is cleared.
   * @see java.sql.Connection#setClientInfo(java.lang.String, java.lang.String)
   */
  public void setClientInfo(String name, String value)
  {
    // Do nothing.
  }



  /**
   * Do nothing.
   * 
   * @param iface
   *          a Class defining an interface.
   * @return true if this implements the interface or directly or indirectly
   *         wraps an object that does.
   * @see java.sql.Wrapper#isWrapperFor(java.lang.Class)
   */
  public boolean isWrapperFor(Class<?> iface)
  {
    // Do nothing.
    return false;
  }



  /**
   * Do nothing.
   * 
   * @param <T>
   *          the type of the unwrapped element
   * @param iface
   *          A Class defining an interface that the result must implement.
   * @return an object that implements the interface. May be a proxy for the
   *         actual implementing object.
   * @see java.sql.Wrapper#unwrap(java.lang.Class)
   */
  public <T> T unwrap(Class<T> iface)
  {
    // Do nothing.
    return null;
  }

}
